package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbKnowledgeBaseConfig;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TbKnowledgeBaseConfigDao {

    @Insert("<script>" +
            "insert into " + DB7TableName.TB_KNOWLEDGE_BASE_CONFIG + " " +
            "( "+
            "attr_name, " +
            "attr_value, " +
            "attr_desc, " +
            "remark, " +
            "create_user, " +
            "create_time, " +
            "update_user, " +
            "update_time, " +
            "status" +
            ")"+
            "values "+
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(" +
            "#{entity.attr_name}, " +
            "#{entity.attr_value}, " +
            "#{entity.attr_desc}, " +
            "#{entity.remark}, " +
            "#{entity.create_user}, " +
            "#{entity.create_time}, " +
            "#{entity.update_user}, " +
            "#{entity.update_time}, " +
            "#{entity.status}" +
            ")"+
            "</foreach>"+
            "</script>"
    )
    Integer insertTbKnowledgeBaseConfigBatch(@Param("entities") List<TbKnowledgeBaseConfig> entities);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_KNOWLEDGE_BASE_CONFIG +
            " where id = #{entity.id} " +
            "</script>")
    Integer deleteTbKnowledgeBaseConfig(@Param("entity") TbKnowledgeBaseConfig entity);

    @Select("<script> " +
            "SELECT * "+
            "FROM " + DB7TableName.TB_KNOWLEDGE_BASE_CONFIG +
            " WHERE 1=1 " +
            "<if test='attr_name != null'> " +
            " AND attr_name = #{attr_name} " +
            "</if> " +
            "</script>")
    List<TbKnowledgeBaseConfig> getByName(@Param("attr_name") String  attr_name);

    @Select("<script> " +
            "SELECT * "+
            "FROM " + DB7TableName.TB_KNOWLEDGE_BASE_CONFIG +
            " WHERE 1=1 " +
            "<if test='attr_name != null'> " +
            " AND attr_name = #{attr_name} " +
            "</if> " +
            "LIMIT 1 "+
            "</script>")
    TbKnowledgeBaseConfig getByName2(@Param("attr_name") String  attr_name);

    @Update("<script>" +
            "UPDATE " + DB7TableName.TB_KNOWLEDGE_BASE_CONFIG + " " +
            "SET " +
            "attr_value = #{entities.attr_value}, " +
            "update_user = #{entities.update_user}, " +
            "update_time = #{entities.update_time} " +
            "WHERE attr_name = #{entities.attr_name} " +
            "</script>")
    Integer UpdateTbKnowledgeBaseConfigByName(@Param("entities") TbKnowledgeBaseConfig entities);




}
